/*
 * Powered By [leyvi]
 * Since 2014 - 2016
 */


var qrcode = {};
var common = require('../../utils/commonUtils');
//db转换成model
qrcode.dbConvertModel = function(db){
	var qrcode = {}; 
	if(common.isNotBlank(db.Id)) qrcode.id = db.Id;	
	if(typeof db.ios_code != "undefined") qrcode.iosCode = db.ios_code;
	if(typeof db.and_code != "undefined") qrcode.andCode = db.and_code;
	if(typeof db.ios_url != "undefined") qrcode.iosUrl = db.ios_url;
	if(typeof db.and_url != "undefined") qrcode.andUrl = db.and_url;
	return qrcode;
};

//model转换成db
qrcode.modelConvertDb = function(obj){
	var db = {}; 
	if(common.isNotBlank(obj.id)) db.Id = obj.id;
	if(typeof obj.iosCode != "undefined") db.ios_code = obj.iosCode;
	if(typeof obj.andCode != "undefined") db.and_code = obj.andCode;
	if(typeof obj.iosUrl != "undefined") db.ios_url = obj.iosUrl;
	if(typeof obj.andUrl != "undefined") db.and_url = obj.andUrl;
	return db;
};

qrcode.initPostReq = function(req){
	var qrcode = {};
	if(req.body.id != undefined){
		(typeof req.body.id != 'string') ? (qrcode.id = req.body.id) : (qrcode.id = req.body.id.trim());
	}
	if(req.body.iosCode != undefined){
		(typeof req.body.iosCode != 'string') ? (qrcode.iosCode = req.body.iosCode) : (qrcode.iosCode = req.body.iosCode.trim());
	}
	if(req.body.andCode != undefined){
		(typeof req.body.andCode != 'string') ? (qrcode.andCode = req.body.andCode) : (qrcode.andCode = req.body.andCode.trim());
	}
	if(req.body.iosUrl != undefined){
		(typeof req.body.iosUrl != 'string') ? (qrcode.iosUrl = req.body.iosUrl) : (qrcode.iosUrl = req.body.iosUrl.trim());
	}
	if(req.body.andUrl != undefined){
		(typeof req.body.andUrl != 'string') ? (qrcode.andUrl = req.body.andUrl) : (qrcode.andUrl = req.body.andUrl.trim());
	}
	return qrcode;
};

qrcode.initGetReq = function(req){
	var qrcode = {};
	if(req.query.id != undefined){	
		(typeof req.query.id != 'string') ? (qrcode.id = req.query.id) : (qrcode.id = req.query.id.trim());
	}
	if(req.query.iosCode != undefined){	
		(typeof req.query.iosCode != 'string') ? (qrcode.iosCode = req.query.iosCode) : (qrcode.iosCode = req.query.iosCode.trim());
	}
	if(req.query.andCode != undefined){	
		(typeof req.query.andCode != 'string') ? (qrcode.andCode = req.query.andCode) : (qrcode.andCode = req.query.andCode.trim());
	}
	if(req.query.iosUrl != undefined){	
		(typeof req.query.iosUrl != 'string') ? (qrcode.iosUrl = req.query.iosUrl) : (qrcode.iosUrl = req.query.iosUrl.trim());
	}
	if(req.query.andUrl != undefined){	
		(typeof req.query.andUrl != 'string') ? (qrcode.andUrl = req.query.andUrl) : (qrcode.andUrl = req.query.andUrl.trim());
	}
	return qrcode;
};


module.exports = qrcode;
